<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
    class Eyeworx_PatientRecords_Transaction_RBO_RBOTransactions extends RBO_Recordset {

//        public function display_amount($record, $nolink=false) {
//            // FRAME
//            $frame = $record['select_frame'];
//            $frame_query = DB::GetOne("SELECT f_price FROM eyeworx_frame_data_1 WHERE f_brand_name = $frame AND f_model_name = $frame");
//            $price = $record['amount'] = $frame_query;
//            var_dump($price);
//            return $price;
//        }

        public function display_amount($record, $nolink = false){
            //FRAME
            $frame = $record['select_frame'];
            $price_frame = DB::Execute("SELECT f_price FROM eyeworx_frame_data_1 WHERE f_brand_name = $frame AND f_model_name = $frame");

            $amount = $record['amount'] = $price_frame;
//            var_dump($amount);
            return $amount;
//            $price =  Utils_CurrencyFieldCommon::get_values($record->amount);
//            var_dump($price);
//            return Utils_CurrencyFieldCommon::format(round($amount[0],2),$price[1]);
        }

        public function QFfield_product_type(&$form,$field,$label,$mode,$default) {
            $type[] = "---";
            $type = $type+Utils_CommonDataCommon::get_array('Eyeworx/PatientRecords/Transaction/productClass');
            load_js('modules/Eyeworx/PatientRecords/Transaction/js/transaction.js');
            eval_js('disable_fields()');
            $form->addElement('select', $field, $label, $type, array('onchange'=>'disable_fields()', 'id'=>'pt'));
        }

        public function fields() {
            $fields = array();

            $patient_name = new RBO_Field_Select('Patient Name', 'eyeworx_patient', array('patient_full_name'));
            $patient_name->set_required()->set_visible();
            $fields[] = $patient_name;

            $prod_class = new RBO_Field_CommonData('Product Type', 'Eyeworx/PatientRecords/Transaction/productClass');
            $fields[] = $prod_class;

            // =================== FRAME
            $frame = new RBO_Field_Select('Select Frame', 'eyeworx_frame', array('frame_brand', 'frame_model'));
            $frame->set_filter();
            $fields[] = $frame;

//            $frame_name = new RBO_Field_Calculated('Frame');
//            $frame_name->set_db_type('text', 128);
//            $frame_name->set_visible();
//            $fields[] = $frame_name;

            $frame_details = new RBO_Field_Calculated('Frame Details');
            $frame_details->set_db_type('text', 128);
            $fields[] = $frame_details;

            // =================== CONTACT LENS
            $contact_lens = new RBO_Field_Select('Select Contact Lens', 'eyeworx_contact_lens', array('contact_lens_brand', 'contact_lens_model'));
            $contact_lens->set_filter();
            $fields[] = $contact_lens;

//            $cl_name = new RBO_Field_Calculated('Contact Lens');
//            $cl_name->set_db_type('text', 128);
//            $cl_name->set_visible();
//            $fields[] = $cl_name;

            $cl_details = new RBO_Field_Calculated('Contact Lens Details');
            $cl_details->set_db_type('text', 128);
            $fields[] = $cl_details;

            // ==================== LENS

            // transaction
            $type = new RBO_Field_CommonData('Transaction Type', 'Eyeworx/PatientRecords/Transaction/type');
            $type->set_visible()->set_filter();
            $fields[] = $type;

            $qty = new RBO_Field_Integer('Quantity');
            $fields[] = $qty;

            $amount = new RBO_Field_Calculated('Amount', 'currency');
            $amount->set_db_type('text', 45);
            $amount->set_visible();
            $fields[] = $amount;

            $discount = new RBO_Field_Float('Discount');
            $fields[] = $discount;

            $total = new RBO_Field_Calculated('Total Amount', 'currency');
            $total->set_db_type('text', 45);
            $total->set_visible();
            $fields[] = $total;

            $amount_paid = new RBO_Field_Currency('Amount Paid');
            $amount_paid->set_visible();
            $fields[] = $amount_paid;

            $balance = new RBO_Field_Calculated('Balance', 'currency');
            $balance->set_db_type('text', 45);
            $balance->set_visible();
            $fields[] = $balance;

            $date_paid = new RBO_Field_Date('Date Paid');
            $date_paid->set_visible();
            $fields[] = $date_paid;

            return $fields;
        }

        public function table_name() {
            return 'eyeworx_patient_transaction';
        }

    }
?>